<?php
/**
 * @package JoiCaddy
 * @copyright Авторские права (C) 2008-2010 Joostina team. Все права защищены.
 * @license Лицензия http://www.gnu.org/licenses/gpl-2.0.htm GNU/GPL, или help/license.php
 * JoiCaddy - свободное программное обеспечение распространяемое по условиям лицензии GNU/GPL
 * JoiCaddy основан на разработках SimpleCaddy от Henk von Pickartz
 */
 
defined('_VALID_MOS') or die();

require_once (JPATH_BASE.DS.'components'.DS.'com_caddy'.DS.'caddy.class.php');
require_once (JPATH_BASE.DS.'components'.DS.'com_caddy'.DS.'caddy.cart.class.php');

global $mosConfig_lang;
$lang = ($mosConfig_lang == '') ? 'russian' : $mosConfig_lang;
require_once (JPATH_BASE.DS.'modules'.DS.'mod_joicaddy'.DS.'lang'.DS.$lang.'.php');

$a=getCaddy();
$itemid	= $params->get('DisplayID');

echo $a;
echo "<div align='center'>
	<form name='frmcheckout' method ='post' action='index.php?option=com_caddy&amp;action=showcart&amp;Itemid=$itemid'>
	<span class='button'>
	    <input type='submit' class='button' name='submit' value='".SC_MOD_SHOW_CART."' />
	</span>
	</form></div>
";

function getCaddy() {
	$cfg=new sc_configuration();
	$tsep=$cfg->get('thousand_sep');
	$dsep=$cfg->get('decimal_sep');
	$decs=$cfg->get('decimals');
	$currency=$cfg->get('currency');
	$curralign=$cfg->get('curralign');
	$cfp=$cfg->get ("taxrate");
	$cfp=str_replace("%", "", $cfp);
	if ($cfp>1) {
		$cfp=$cfp/100;
	}
	$taxrate=$cfp;

	$cart2=new cart2();
	$cart=$cart2->readCart();
	if (!$cart) {
		echo SC_MOD_CART_EMPTY;
		return;
	}
	$gtotal=0;
	$nombre=0;
	$emptycart=true;
	$html = "<table width='100%' border='0'>";
	$nombre=$cart2->getCartNumbers();
	$gtotal=$cart2->getCartTotal();
	if ($nombre==0) {
		$html=SC_MOD_CART_EMPTY;
	}
	else
	{
		$subtotal=$gtotal;
		$tax = $gtotal*$taxrate;
		$total=$subtotal+$tax;
		$tax=number_format($tax, $decs, $dsep, $tsep);
		$subtotal=number_format($subtotal, $decs, $dsep, $tsep);
		$total=number_format($total, $decs, $dsep, $tsep);
		$subtotal=($curralign==1?"$currency&nbsp;$subtotal":"$subtotal&nbsp;$currency");
		$stax=($curralign==1?"$currency&nbsp;$tax":"$tax&nbsp;$currency");
		$stotal=($curralign==1?"$currency&nbsp;$total":"$total&nbsp;$currency");

		$html .="<tr><td colspan=2>".SC_MOD_YOUR_CART_CONTAINS." <strong>$nombre</strong> ".(($nombre==1)?SC_MOD_PRODUCT:SC_MOD_PRODUCTS)."</td></tr>";

		if ($taxrate>0){
			$html .="<tr><td>".SC_MOD_SUBTOTAL."</td><td align=right nowrap=1>".$subtotal."</td></tr>";
			$html .="<tr><td>".SC_MOD_TAX."</td><td align=right nowrap=1>".$stax."</td></tr>";
			$html .="<tr><td>".SC_MOD_TOTAL."</td><td align=right nowrap=1>".$stotal."</td></tr>";
			
		}
		else
		{
			$html .="<tr><td>".SC_MOD_TOTAL."</td><td align=right nowrap=1>".$stotal."</td></tr>";
		}

		$html .="</table>";
	}
	return $html;
}
?>
